package com.surveypark.struts2.interceptor;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.surveypark.struts2.action.BaseAction;
import com.surveypark.util.ValidateUtil;

public class RightFilterInterceptor implements Interceptor{

	/**
	 * 权限过滤拦截器
	 */
	private static final long serialVersionUID = 2309298086810930970L;

	@Override
	public void destroy() {
		
	}

	@Override
	public void init() {
		
	}

	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		
		@SuppressWarnings("rawtypes")
		BaseAction action = (BaseAction) arg0.getAction();
		ActionProxy proxy = arg0.getProxy();
		String ns = proxy.getNamespace();
		String actionName = proxy.getActionName();
		if(ValidateUtil.hasRight(ns, actionName, ServletActionContext.getRequest(), action)){
			return arg0.invoke();
		}else{
			return "no_right_error";//没有权限
		}
	}

}
